package com.mzp.XbShop.controller;

import com.mzp.XbShop.common.entity.Result;
import com.mzp.XbShop.common.entity.StatusCode;
import com.mzp.XbShop.pojo.UserFavorGoods;
import com.mzp.XbShop.service.UserFavorGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author admin
 * @Description user_favor_goods 控制器层
 * @date 2021-04-19 22:50:00
 */
@RestController
@CrossOrigin
@RequestMapping("/userFavorGoods")
public class userFavorGoodsController {
    @Autowired
    private UserFavorGoodsService userFavorGoodsService;

    //通过用户id找收藏的商品

    @RequestMapping("/findByUserIdFavorGoods/{userId}")
    public Result findByUserIdFavorGoods(@PathVariable String userId){
       return new Result(true, StatusCode.OK,"查找成功",userFavorGoodsService.findByUserIdFavorGoods(userId));
    }

    //添加收藏
    @PostMapping("/insert")
    public Result insert(@RequestBody UserFavorGoods userFavorGoods){
        return new Result(true, StatusCode.OK,"查找成功",userFavorGoodsService.insert(userFavorGoods));
    }
    /**
     * 取消收藏
     *
     */
    @GetMapping("/deleteFavor/{goodsid}/{userid}")
    public Result deleteFavor(@PathVariable String goodsid,@PathVariable String userid){
        userFavorGoodsService.deleteFavor(goodsid,userid);
        return new Result(true, StatusCode.OK,"取消收藏成功");
    }

    @GetMapping("/addFavor/{goodsid}/{userid}")
    public Result addFavor(@PathVariable String goodsid,@PathVariable String userid){
        Integer num=userFavorGoodsService.addFavor(goodsid,userid);
        return new Result(true, StatusCode.OK,"收藏成功");
    }

    /**
     * 添加收藏 addFavor
     */
    /**
     * 查看是否该用户id是否
     */
    @GetMapping("/exits/{goodsid}/{userid}")
    public Result exits(@PathVariable String goodsid,@PathVariable String userid){
        return new Result(true, StatusCode.OK,"查找成功",userFavorGoodsService.findByGoodsid(goodsid,userid));
    }
}
